<% content_for :title do %>Product aanpassen<% end %>

<h2>Product gegevens</h2>
<% form_for(@product, :url => admin_product_path(@product)) do |f| %>
  <%= f.error_messages %>

  <p>
    <%= f.label :name, 'Naam'%><br />
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.label :stock, 'Voorraad'%><br />
    <%= f.text_field :stock %>
  </p>
  <p>
    <%= f.label :price, 'Prijs'%><br />
    <%= f.text_field :price %>
  </p>
  <p>
    <%= f.label :description, 'Omschrijving'%><br />
    <%= f.text_area :description, :cols => 70, :rows => 5, :onfocus => 'this.rows=25', :onblur => 'this.rows=5' %>
  </p>
  <p>
    <%= f.submit 'Update' %>
  </p>
<% end %>

  <h2>Afbeelding</h2>
  <p>
  <% if @product.image.exists? %>
  <%=product_image @product, :thumbnail %>
  <% else %>
  Geen
  <% end %>
  </p>


  <%=link_to 'Uploaden', admin_product_image_path(@product) %>
  <% if @product.image.exists? %>
  | <%=link_to 'Verwijderen', admin_product_image_path(@product), :method => :delete, :confirm => 'Weet u zeker dat u deze afbeelding wilt verwijderen.' %>
  <% end %>

  <h2>Attributen</h2>
  <%=render :partial => 'admin/product_attributes/table', :locals => {:product =>  @product} %>


  <div id="new_product_attribute" style="display: none;">
<% form_remote_for 'product_attribute', :url => admin_product_attributes_path(@product), :method => :post do |f| %>

    <p>
      Attribuut:<br />
      <%=f.collection_select :attribute_id, @attributes, :id, :name, {}, {:style => 'width: 200px'} %>
    </p>

    <p>
      Waarde:<br />
      <%=f.text_field :value %>
    </p>

    <p>
      <%=f.submit 'Attribuut toevoegen' %>
    </p>

<% end %>
  </div>

<%=link_to_function "Attribuut toevoegen", "$('new_product_attribute').toggle()" %>





  <h2>Categorie&euml;n</h2>
  <%=render :partial => 'admin/product_categories/table', :locals => {:product => @product} %>

  <div id="new_product_category" style="display: none;">
<% form_remote_for 'product_category', :url => admin_product_categories_path(@product), :method => :post do |f| %>
<%=f.select :category_id, format_categories_options(@categories, 0, false) %>
<%=f.submit 'In categorie zetten' %>
<% end %>
  </div>

<%=link_to_function "Product in categorie zetten", "$('new_product_category').toggle()" %>


  <br /><br />
<%= link_to 'Show', product_path( @product ) %> |
<%= link_to 'Terug', admin_products_path %>